package com.xajh.duoduo.controller;

import com.xajh.duoduo.abs.AbsProcessor;
import com.xajh.duoduo.environment.CurrentRolePosition;
import com.xajh.duoduo.eunm.position.RolePosition;
import com.xajh.duoduo.manager.ProcessorManger;
import com.xajh.duoduo.service.OneProcessService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Controller
public class ProcessController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());

    @Autowired
    private OneProcessService oneProcessService;
    @Autowired
    private ProcessorManger processorManger;

    /**
     * 练级接口
     */
    @RequestMapping(value = "/oneProcess", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public void oneProcess(HttpServletRequest request, HttpServletResponse response){
        String type = request.getParameter("type");
        String processSwitch = request.getParameter("switch");
        //针对切换角色，需要告知现在是第几个了
        String itemIndex = request.getParameter("itemIndex");
        try {
            oneProcessService.oneProcess(type,processSwitch,itemIndex);
        } catch (Exception e) {
            AbsProcessor absProcessor = (AbsProcessor) processorManger.initProcessor(type);
            logger.error("流程执行失败，GlobleId= {}。Exception={}",absProcessor.generateGlobleId(),e);
            e.printStackTrace();
        }
    }

}
